

setcookie($name, $value, 0);echo "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
echo getcwd();
<?php
/*
* When controller.php is accessed for the first time
*/
if (empty($_POST['page'])) {
$display_modal_window = 'none';
include ('view_startpage.php');
exit;
}
/*
* When commands come from StartPage or MainPage
*/
require ('model.php'); // connect to MySQL database; functions to access DB tables
$page = $_POST['page'];
$command = $_POST['command'];
if ($page == 'StartPage')
{
switch ($command) {
case 'SignIn':
$username = ????;
$password = ????;
// When the user is valid,
if (is_valid(???, ???) { // is_valid() is in model.php
???('username', $username, time() + 24 * 60 * 60); // Set a cookie for a welcoming message on StartPage for the next visit
include('view_mainpage.php');
}
// When invalid
else {
$display_modal_window = 'signin';
$error_msg_username = '* Wrong username, or';
$error_msg_password = '* Wrong password';
include('view_startpage.php');
}
break;
...
}
}
else if ($page == 'MainPage')
{
...
}
else {
...
}
?>
<div id='welcome-message' style='display:???'></div>
<script>
<?php
if (!empty($_???['username'])) { // COOKIE super global array
echo "document.getElementById('welcome-message').???? = 'Welcome back, " .
$_???['username'] . "!';";
echo "document.getElementById('welcome-message').???? = 'block';";
// destroy the cookie
???('username', '', ????);
}
?>
</script>

session_start() do? The return value of this function is TRUE or FALSE.
<?php
/*
* When controller.php is accessed for the first time
*/
if (empty($_POST['page'])) {
$display_modal_window = 'none';
include ('view_startpage.php');
exit;
}
/*
* When commands come from StartPage or MainPage
*/
require ('model.php'); // connect to MySQL database; functions to access DB tables
$page = $_POST['page'];
$command = $_POST['command'];
if ($page == 'StartPage')
{
switch ($command) {
case 'SignIn':
$username = ???;
$password = ???;
// When the user is valid,
if (is_valid(???, ???) { // is_valid() is in model.php
setcookie('username', $username, time() + 24 * 60 * 60); // Set a cookie for a welcoming message on StartPage for the next visit
session_start();
$_SESSION['signedin'] = 'YES'; // session variable - for commands coming from MainPage
????['username'] = $username; // session variable - for command coming from MainPage
include('view_mainpage.php');
}
// When invalid
else {
$display_modal_window = 'signin';
$error_msg_username = '* Wrong username, or';
$error_msg_password = '* Wrong password';
include('view_startpage.php');
}
break;
...
}
}
else if ($page == 'MainPage')
{
session_start(); // in order to access session variables
// What if a user used MainPage without going through the user authentication process?
if (!isset($_SESSION['signedin'])) {
$display_modal_window = 'none';
include ('view_startpage.php');
exit;
}
$username = $_SESSION['username'];
switch ($command) {
case 'SignOut': // 'SignOut' menu item, or timeout
session_unset();
session_destroy(); // It does not unset session variables. session_unset() is needed.
$display_modal_window = 'none';
include ('view_startpage.php');
break;
case 'SearchQestions': // It uses $username.
...;
break;
...
}
}
else {
...
}
?>
<?php
// session_start(); // Session is started in controller.php before mainpage.php is included.
if (empty($_SESSION['signedin'])) {
$display_modal_window = 'none';
include('view_startpage.php');
exit;
}
?>
...
<script>
...
var timer = setTimeout(timeout, 10 * 60 * 1000);
window.addEventListener('mousemove', event_listener_mousemove_or_keydown); // mousemove on the screen
window.addEventListener(???, ???); // for keyboard action
window.addEventListener('???', function() { // when the window is closed
???? // ...
});
function event_listener_mousemove_or_keydown() {
clearTimeout(???);
timer = setTimeout(timeout, 10 * 60 * 1000);
}
function timeout() {
???? // send the 'SignOut' command to the controller
}
...
</script>
<form id='form-signout' method='POST' action='???' ????>
<input type='hidden' name='page' value='???'>
<input type='hidden' name='???' value='SignOut'>
</form>
<script>
...
function timeout() {
...
document.getElementById('form-signout').???(); // submit the form with the 'SignOut' command
}
...
</script>